<template>
    <div>
        <el-dialog title="已关联的数据" :visible.sync="queryOpen" width="50%" append-to-body :before-close="closeDelDialog">

            <el-row :gutter="10" class="mb8" ref="refbut">
                <el-col :span="1.5">
                    <el-button @click="deleteTap" v-if="hjhaoType!='2'">批量删除</el-button>
                </el-col>
            </el-row>
            <el-table v-loading="loading" :data="list" @selection-change="handleSelectionChange" border height="500px"
                @cell-dblclick="celldblclick">
                <el-table-column type="selection" width="50" align="center" />
                <el-table-column label="序号" type="index" />
                <el-table-column label="档案标题" align="center" prop="title" :show-overflow-tooltip="true" />
                <el-table-column label="档号" align="center" prop="dh" :show-overflow-tooltip="true" />
                <el-table-column label="年度" align="center" prop="nd" :show-overflow-tooltip="true" />
                <el-table-column label="保管期限" align="center" prop="bgqx" width="120">
                    <template slot-scope="scope">
                        <span v-for="(i, idx) in dict.type.BGQX" :key="idx">
                            {{ scope.row.bgqx == i.value ? i.label : '' }}
                        </span>
                    </template>
                </el-table-column>
                <el-table-column label="全宗号" align="center" prop="qzh" width="120"></el-table-column>
            </el-table>
            <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
                :limit.sync="queryParams.pageSize" @pagination="getList" />
        </el-dialog>
        <!--start  组件详情 -->
        <jiancomponen v-if="jianDetailsOpen" :open="jianDetailsOpen" :celldbData="celldbDatajh"
            @detailsHandleClose="detailsHandleClose">
        </jiancomponen>
        <!--end 组件详情 -->
        <!-- start 组卷\项目详情 -->
        <juanDetailsOpen v-if="juanDetailsOpen" :open="juanDetailsOpen" :celldbData="celldbDatajh"
            @detailsHandleClose="detailsHandleClose"></juanDetailsOpen>
        <!-- end 组卷\项目详情 -->
    </div>
</template>
<script>
import {
    associationList, associationDelete, getRole,getDocRole
} from "@/api/archive/filesManage/filesManageMenu.js" //档案管理
import { getLastIndexOf } from "@/utils/index.js"
import { getthbytreenodeHeaderList } from "@/api/archive/fileCollection/offlinReception.js";
import jiancomponen from '@/components/componentsJianDetailsCopy/index.vue' //件详情
import juanDetailsOpen from '@/components/componentsJuanDetails/index.vue' //卷详情'
export default {
    components: {
        jiancomponen, juanDetailsOpen
    },
    
    // <!--start 已关联的互见号  hjhaoType==1 '档案整理'  hjhaoType==2 '（目录检索，全文检索）'-->
    props: ['queryOpen', 'daId', 'menuId','hjhaoType'],
    archive_Dicts: ['BGQX'],
    watch: {
        daId: {
            handler(valNew) {
                console.log(valNew,"hujianhao")
                this.queryParams["daId"]=valNew
                this.getList()
          
            },
            immediate: true
        }
    },
    data() {
        return {
            loading: true,
            list: [],
            total: 0,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            queryParams: {
                pageNum: 1,
                pageSize: 10
            },
            jianDetailsOpen: false,
            juanDetailsOpen: false,

            celldbDatajh: undefined
        }
    },
    methods: {






        // 多选框选中数据
        handleSelectionChange(selection) {
            this.ids = selection.map(item => item.id);
            this.single = selection.length != 1;
            this.multiple = !selection.length;
        },
        closeDelDialog() {
            this.$emit("closeDelDialog")
        },
        deleteTap() {
            if(!this.multiple){
                associationDelete(this.ids.toString()).then(res => {
                if (res.code == "200") {
                    this.$modal.msgSuccess("已删除关联的数据")
                    this.getList();
                }
            })
            }else{
                this.$message({ message: '请选择要删除的数据哦！', type: 'warning' })
            }
                
          
        },
        getList(daId) {
            
            associationList(this.queryParams).then(res => {
                this.list = res.rows;
                this.total = res.total;
                this.loading = false;
            })
        },
        //双击列表进入详情页面
        celldblclick(row) {
            // console.log(row,"000000000000")
             console.log(row,this.hjhaoType,"11111111111liuhaiorng")  //判断接口权限

            if(this.hjhaoType=='2'){  //是否可以看到档案全文权限（目录检索，全文检索）
                getDocRole(
                    {
                        daId: row.glId,
                        menuId: this.menuId,
                    }
                ).then(res=>{
                   //返回数据  true 可看详情，false 不能查看详情
           
                if (res.data) {
                    var level = "";
                    var label = "";
                    getthbytreenodeHeaderList({
                        categoryId: row.categoryId,
                        menuId: this.menuId,
                        subTableName: row.subTableName
                    }
                    ).then(response => {

                        // console.log(response,"00000000000000000000000000")
                        var tableHeaderList = response.rows;


                        if (getLastIndexOf(row.subTableName) == "F") {  //F 件
                            level = 0
                            label = row.title;
                        } else if (getLastIndexOf(row.subTableName) == "V") { //卷
                            level = 1
                            label = row.title;
                        } else { //项目
                            level = 3
                            label = row.xmmc;

                        }
                        this.celldbDatajh = {
                            id: row.glId,
                            categoryId: row.categoryId,
                            menuId: this.menuId,
                            sub_table_name: row.subTableName,
                            label: label,
                            level: level,
                            ifSub_table_name: row.subTableName,
                            isDel: "0",  //判断是回收站数据还是接收收据 isDel:1  回收站    isDel:0 //离线接收、档案接收、在线接收
                            tableHeaderList: tableHeaderList
                        }
                        this.$nextTick(() => {
                            if (getLastIndexOf(row.subTableName) == "F") {  //F 进入件详情
                                this.jianDetailsOpen = true;
                            } else { //进入卷详情 和项目详情
                                this.juanDetailsOpen = true
                            }
                        })




                    })

                } else {
                    this.$message({ message: '该用户没有权限查看详情哦！', type: 'warning' })
                }
                })
            }else{ //是否可以看到档案全文权限（档案管理）
                
            getRole({
                categoryId: row.categoryId,
                menuId: this.menuId,
            }).then(res => {
                //返回数据  true 可看详情，false 不能查看详情
                if (res.data) {
                    var level = "";
                    var label = "";
                    getthbytreenodeHeaderList({
                        categoryId: row.categoryId,
                        menuId: this.menuId,
                        subTableName: row.subTableName
                    }
                    ).then(response => {
                        var tableHeaderList = response.rows;


                        if (getLastIndexOf(row.subTableName) == "F") {  //F 件
                            level = 0
                            label = row.title;
                        } else if (getLastIndexOf(row.subTableName) == "V") { //卷
                            level = 1
                            label = row.title;
                        } else { //项目
                            level = 3
                            label = row.xmmc;

                        }
                        this.celldbDatajh = {
                            id: row.glId,
                            categoryId: row.categoryId,
                            menuId: this.menuId,
                            sub_table_name: row.subTableName,
                            label: label,
                            level: level,
                            ifSub_table_name: row.subTableName,
                            isDel: "0",  //判断是回收站数据还是接收收据 isDel:1  回收站    isDel:0 //离线接收、档案接收、在线接收
                            tableHeaderList: tableHeaderList
                        }
                        this.$nextTick(() => {
                            if (getLastIndexOf(row.subTableName) == "F") {  //F 进入件详情
                                this.jianDetailsOpen = true;
                            } else { //进入卷详情 和项目详情
                                this.juanDetailsOpen = true
                            }
                        })




                    })

                } else {
                    this.$message({ message: '该用户没有权限查看详情哦！', type: 'warning' })
                }
            })
        }
        },


        //关闭详情页面
        detailsHandleClose() {
            this.jianDetailsOpen = false;
            this.juanDetailsOpen = false;
        },


    }
}
</script>
<style lang="scss" scoped></style>